define(['jquery', 'bootstrap', 'backend', 'table', 'form','cookie'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'thm/userinfolog/index',
                    add_url: 'thm/userinfolog/add',
                    edit_url: 'thm/userinfolog/edit',
                    del_url: 'thm/userinfolog/del',
                    multi_url: 'thm/userinfolog/multi',
                    table: 'thm_userinfolog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showExport: false,
                //searchFormVisible: true,
                columns: [
                    [
                        //{checkbox: true},
                        //{field: 'id', title: __('Id')},
                        {field: 'create_time', title: __('Create_time'), operate: false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'user.mobile', title: __('User.mobile'), operate: false},
                        {field: 'content1', title: Config.titles.t1, operate: false},
                        {field: 'content2', title: Config.titles.t2, operate: false},
                        {field: 'content3', title: Config.titles.t3, operate: false},
                        {field: 'content4', title: Config.titles.t4, operate: false},
                        {field: 'content5', title: Config.titles.t5, operate: false},
                        {field: 'content6', title: Config.titles.t6, operate: false},
                        {field: 'content7', title: Config.titles.t7, operate: false},
                        {field: 'image7', title: __('圖片7'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'content8', title: Config.titles.t8, operate: false},
                        {field: 'image8', title: __('圖片8'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                    //    {field: 'user.id', title: __('User.id')},
                    //    {field: 'user.app_id', title: __('User.app_id')},
                    //    {field: 'user.name', title: __('User.name')},
                    //    {field: 'user.mobile', title: __('User.mobile')},
                    //    {field: 'user.zfmobile', title: __('User.zfmobile')},
                    //    {field: 'user.sjxh', title: __('User.sjxh')},
                    //    {field: 'user.online', title: __('User.online')},
                    //    {field: 'user.switch', title: __('User.switch'), formatter: Table.api.formatter.toggle},
                    //    {field: 'user.latlon', title: __('User.latlon')},
                    //    {field: 'user.create_time', title: __('User.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                    //    {field: 'user.update_time', title: __('User.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                    //    {field: 'user.online_time', title: __('User.online_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                    //    {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 选择隐藏字段事件，使用cookie存入
            table.on('column-switch.bs.table', function (e, json) {
                    var myColumns=[];
                    $.each(table.bootstrapTable('getHiddenColumns'), function(i, item) {
                         myColumns.push(item.field);
                    });
                    $.cookie('fa_thm_userinfolog', JSON.stringify(myColumns), { expires: 365, path: '/'});
             });
             if($.cookie('fa_thm_userinfolog')){
                //读取cookie隐藏字段
                $.each(JSON.parse($.cookie('fa_thm_userinfolog')), function(i, item) {
                  table.bootstrapTable('hideColumn', item);
                });
             }

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});